<template>
  <div class="app-container">
    <div class="filter-container">
      <span style="float:left;width:30%;">
        <el-input @keyup.enter.native="handleFilter" v-model="listQuery.uuid" placeholder="请输入查询信息" class="filter-item" />
      </span>
      <span style="float:left;margin-left: 10px;">
        <el-button @click="handleFilter" class="filter-item" type="primary" v-waves icon="el-icon-search">查询</el-button>
        <el-button @click="handleCreate" v-if="baseAddr_btn_add" :disabled="btnDisabled"
               class="filter-item" type="primary" v-waves icon="el-icon-plus">添加
        </el-button>
      </span>
    </div>
    <!-- 表格 -->
    <el-table :data="list" row-key="id" lazy :load="load" :tree-props="treeProps" v-loading="listLoading" style="width: 100%;height: 100%;" border >
      
      <el-table-column prop="adCd" label="行政区划代码" width="200px" align="center" />
      <el-table-column prop="adNm" label="行政区划名称" align="center" />
      <el-table-column prop="adShnm" label="行政区划简称" width="200px" align="center" />
      <el-table-column prop="level" label="层级" width="100px" align="center" />
      <el-table-column prop="status" label="状态" width="80px" align="center" />

      <el-table-column align="center" label="操作" width="200">
        <template slot-scope="scope">
          <el-button v-if="baseAddr_btn_edit" @click="handleUpdate(scope.row.id)" size="small" type="success">修改</el-button>
          <el-button v-if="baseAddr_btn_del" @click="handleDelete(scope.row.id)" size="small" type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加修改弹出框页面组件 -->
    <add-update v-if="showAdd" @flushList="flushList" @closeDialog="closeDialog" :restPath="restPath" :showAdd="showAdd" :btnType="btnType" :rowId="rowId" :typeOps="typeOps" />

  </div>
</template>

<script>
  /* mixins */
  import pageListMixin from '@/mixins/pageList/pageListMixin.js'
  
  /* 组件 */
  import addUpdate from './addUpdate.vue'
  
  import {
    loadFirstAddrTree,
    getSonAddrTree,
  } from '@/api/sys/addr'

  export default {
    /*  内容: 行政分区  */
    name: 'addr',
    data() {
      return {
        restPath: 'sys/addr',
        listQuery: {
          adCd: '',
        },
        baseAddr_btn_edit: true,
        baseAddr_btn_del: true,
        baseAddr_btn_add: true,
        
        treeProps: {
          children: 'children', 
          hasChildren: 'hasChildren'
        }
      }
    },
    mixins: [pageListMixin],
    components: {
      'add-update': addUpdate,
    },
    methods: {
      initData() {
        //              this.baseAddr_btn_edit = this.elements['baseAddr:btn_edit']
        //              this.baseAddr_btn_del = this.elements['baseAddr:btn_del']
        //              this.baseAddr_btn_add = this.elements['baseAddr:btn_add']

        this.getList()
      },
      
      
      /**
       * 后台获取列表数据
       */
      getList() {
        this.listLoading = true
        loadFirstAddrTree(this.listQuery).then(response => {
          this.list = response.data
          this.listLoading = false
        }).catch(err => {
          this.listLoading = false;
          this.btnDisabled = true // 按钮禁用
          console.error(err)
        })
      },
      
      load(tree, treeNode, resolve) {
        setTimeout(() => {
          resolve([
            
          ])
        }, 1000)
      },

    } // methods end
  }
</script>
<style scoped>
  @import "~@/styles/list.css";
</style>